//
//  DateSplitString.swift
//  Memo
//
//  Created by 苏泊尔漫也要按时吃饭 on 4/28/22.
//

import Foundation
import UIKit

extension String {
    
    func dateSplitTotime() -> (year: Int ,month: Int, day: Int) {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "YYYY.MM.dd"
        let dateString: Date = dateFormatter.date(from: self)!
        let calendar = Calendar.current
        let dateComponents = calendar.dateComponents(in: TimeZone.current, from: dateString)
        return (Int(dateComponents.year!),Int(dateComponents.month!),Int(dateComponents.day!))
    }
    
    func stringConvertDate() -> Date {
        let dateFormatter = DateFormatter.init()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        let date = dateFormatter.date(from: self)
        return date!
    }

}

extension NSString {
    func dateSliteToHourAndMinute() ->(hour: Int,minute: Int) {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "hh.mm"
        let dateString: Date = dateFormatter.date(from: self as String)!
        let calendar = Calendar.current
        let dateComponents = calendar.dateComponents(in: TimeZone.current, from: dateString)
        return (Int(dateComponents.hour!),Int(dateComponents.minute!))
    }
    
    func dateTohour() ->(NSMutableArray) {
        let time = self.dateSliteToHourAndMinute()
        let arr: NSMutableArray = NSMutableArray()
        arr.add(time.hour)
        arr.add(time.minute)
        return arr
    }
    

}
